home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 June: Reference Library / Dev.CD Jun 99 RL Disk 1.toast / Technical Documentation / Develop / Additional Articles / Developing Symbiotic Apps / Symbiotic Samples / Symbiotic client source / Trident.cw10_pp / CTridentApp.cp next >
Encoding:
Text File  |  1996-10-15  |  6.8 KB  |  286 lines  |  [TEXT/CWIE]

  1. // ===========================================================================
  2. //    CTridentApp.cp                    ©1993 Metrowerks Inc. All rights reserved.
  3. // ===========================================================================
  4.  
  5. #include "CTridentApp.h"
  6. #include "TridentAESuite.h"
  7. #include "CTridentCmds.h"
  8. #include "CTridentView.h"
  9. #include "CTridentwhoView.h"
  10. #include "CTridentuptimeView.h"
  11.  
  12. #include <LFile.h>
  13. #include <LListener.h>
  14. #include <LView.h>
  15. #include <LWindow.h>
  16. #include <LTable.h>
  17. #include <LTextEdit.h>
  18. #include <LPrintout.h>
  19. #include <LPlaceHolder.h>
  20. #include <LGrowZone.h>
  21. #include <UMemoryMgr.h>
  22. #include <LUndoer.h>
  23. #include <URegistrar.h>
  24. #include <UReanimator.h>
  25. #include <UPrintingMgr.h>
  26. #include <UDesktop.h>
  27. #include <UDrawingState.h>
  28. #include <PP_Messages.h>
  29. #include <PPobClasses.h>
  30. #include <Sound.h>
  31.  
  32. #ifndef __STANDARDFILE__
  33. #include <StandardFile.h>
  34. #endif
  35.  
  36. #define        cmd_whoView        900
  37. #define        cmd_uptimeView    1000
  38. #define   cConfig10             421;
  39. #define   cConfig30             422;
  40. #define   cConfig60             423;
  41. #define   cConfig600         424;
  42. #define   cConfig3600        425;
  43.  
  44. class CTridentView;
  45. class CTridentwhoView;
  46. class CTridentuptimeView;
  47. // ===========================================================================
  48. //        • Main Program
  49. // ===========================================================================
  50.  
  51. void main(void)
  52. {
  53.     SetDebugThrow_(debugAction_Alert);
  54.     SetDebugSignal_(debugAction_Alert);
  55.  
  56.     InitializeHeap(3);
  57.     UQDGlobals::InitializeToolbox(&qd);
  58.     new LGrowZone(20000);
  59.     
  60.     CTridentApp    theApp;
  61.     theApp.Run();
  62. }
  63.  
  64.  
  65. // ---------------------------------------------------------------------------
  66. //        • CTridentApp
  67. // ---------------------------------------------------------------------------
  68. //    Default constructor
  69.  
  70. CTridentApp::CTridentApp()
  71. {
  72.     fDocumentCount = 0;
  73.     RegisterAllPPClasses();
  74.     URegistrar::RegisterClass('wind', (ClassCreatorFunc) CTridentWindow::CreateTridentWindowStream);
  75.     URegistrar::RegisterClass('vwvw', (ClassCreatorFunc) CTridentView::CreateTridentViewStream);
  76.     URegistrar::RegisterClass('vwaa', (ClassCreatorFunc) CTridentwhoView::CreateTridentViewStreamA);
  77.     URegistrar::RegisterClass('vwbb', (ClassCreatorFunc) CTridentuptimeView::CreateTridentViewStreamB);
  78. }
  79.  
  80.  
  81. // ---------------------------------------------------------------------------
  82. //        • ~CTridentApp
  83. // ---------------------------------------------------------------------------
  84. //    Destructor
  85. //
  86.  
  87. CTridentApp::~CTridentApp()
  88. {
  89.  
  90. }
  91.  
  92. void
  93. CTridentApp::HandleNewConnection(ResIDT theWinID)
  94. {
  95.     CTridentWindow* myWindow = (CTridentWindow*) LWindow::CreateWindow(theWinID, this);
  96.     myWindow->SetPortRefNum(fDocumentCount++);
  97.  
  98.     myWindowList.InsertItemsAt(1, arrayIndex_Last, &myWindow);    //has to be here early to handle apple events
  99.     ((CTridentWindow*)myWindow)->Connect();                    
  100.  
  101.     if (!myWindow->IsConnected())
  102.         {
  103.         myWindowList.Remove(&myWindow);
  104.         delete myWindow;
  105.         return;   //command handled
  106.         }
  107.     CTridentView* myListBox = (CTridentView*) myWindow->myView;     //gets set in send version if "S"uccess
  108.         
  109.     if (myListBox)
  110.         {
  111.         ListHandle theList = myListBox->GetMacListH();
  112.         LAddColumn(1,0, theList);
  113.         }
  114.  
  115.     ((CTridentWindow*)myWindow)->SendInterval(30);                    
  116.     ((CTridentWindow*)myWindow)->SendHeart();                    
  117.  
  118. }
  119.  
  120. Boolean
  121. CTridentApp::ObeyCommand(
  122.     CommandT    inCommand,
  123.     void        *ioParam)
  124. {
  125.     Boolean        cmdHandled = true;
  126.     switch (inCommand) {
  127.     
  128.         case cmd_whoView:
  129.             this->HandleNewConnection(cmd_whoView);            
  130.             cmdHandled = TRUE;
  131.             break;
  132.  
  133.         case cmd_uptimeView:
  134.             {                            // EXAMPLE, create a new window
  135.             this->HandleNewConnection(cmd_uptimeView);            
  136.             cmdHandled = TRUE;
  137.             break;
  138.             }
  139.         default:
  140.             cmdHandled = LApplication::ObeyCommand(inCommand, ioParam);
  141.             break;
  142.     }
  143.     
  144.     return cmdHandled;
  145. }
  146.  
  147.  
  148.  
  149. void
  150. CTridentApp::FindCommandStatus(
  151.     CommandT    inCommand,
  152.     Boolean        &outEnabled,
  153.     Boolean        &outUsesMark,
  154.     Char16        &outMark,
  155.     Str255        outName)
  156. {
  157.  
  158.     switch (inCommand) {
  159.     
  160.         // Return menu item status according to command messages.
  161.         // Any that you don't handle will be passed to LApplication
  162.         case 421:
  163.         case 422:
  164.         case 423:
  165.         case 424:
  166.         case 425:
  167.             if (myWindowList.GetCount() > 0)
  168.                 {
  169.                 CTridentWindow *theFrontWindow = NULL;
  170.  
  171.                 LListIterator iterator(myWindowList, iterate_FromStart);
  172.                 CTridentWindow    *theSub;
  173.                 while (iterator.Next(&theSub)) {
  174.                     if (UDesktop::WindowIsSelected(theSub))
  175.                         {
  176.                         theFrontWindow = theSub;
  177.                         continue;
  178.                         }
  179.                 }
  180.         
  181.                 if (theFrontWindow != NULL)
  182.                     theFrontWindow->FindCommandStatus(inCommand, outEnabled, outUsesMark, outMark, outName);
  183.                 
  184.                 }
  185.             break;
  186.             
  187.         case cmd_whoView:                    // EXAMPLE
  188.             outEnabled = TRUE;            // enable the New command
  189.             break;
  190.  
  191.         case cmd_uptimeView:                    // EXAMPLE
  192.             outEnabled = TRUE;            // enable the New command
  193.             break;        default:
  194.             LApplication::FindCommandStatus(inCommand, outEnabled,
  195.                                                 outUsesMark, outMark, outName);
  196.             break;
  197.     }
  198. }
  199.  
  200. void
  201. CTridentApp::HandleAppleEvent(
  202.     const AppleEvent    &inAppleEvent,
  203.     AppleEvent            &outAEReply,
  204.     AEDesc                &outResult,
  205.     long                inAENumber)
  206. {
  207.     OSErr err;
  208. //    LStr255 theText = "this is a test";
  209. //    char string[1024];
  210.     DescType actualCode;
  211.     long actualSize;
  212.     CTridentWindow* theWindow;
  213.     long theConnectionNumber;
  214. //    LListBox* myListBox;
  215.  
  216.     switch (inAENumber) {
  217.     
  218.         case ae_Close:
  219.             SysBeep(3);
  220.             break;
  221.         case kAEJavMsg:
  222.         case keyMessageCode:
  223.         case 407:
  224.         case 408:
  225.             err = ::AEGetParamPtr(&inAppleEvent, keySessionID, typeLongInteger, &actualCode, (Ptr) & theConnectionNumber, sizeof(theConnectionNumber), &actualSize);
  226.             theWindow = this->LocateWindowBySession(theConnectionNumber);
  227.             if (theWindow!= NULL)
  228.                 theWindow->HandleAppleEvent(inAppleEvent, outAEReply, outResult, inAENumber);
  229.             break;
  230.             
  231.         default:
  232.  
  233.             inherited::HandleAppleEvent(inAppleEvent, outAEReply,
  234.                                 outResult, inAENumber);
  235.             break;
  236.     }
  237. }
  238.  
  239. CTridentWindow* CTridentApp::LocateWindowBySession(short theSessionID)
  240. {
  241.     CTridentWindow* theWindow = NULL;
  242.      
  243.     LListIterator iterator(myWindowList, iterate_FromStart);
  244.     CTridentWindow    *theSub;
  245.     while (iterator.Next(&theSub)) {
  246.         if (theSessionID == theSub->fPortRefNum)
  247.             theWindow = theSub;
  248.         if (theWindow != nil) break;
  249.     }
  250.     return theWindow;
  251. }
  252.             
  253. CTridentWindow* CTridentApp::LocateWindowByPaneIDT(PaneIDT thePaneIDT)
  254. {
  255.     CTridentWindow* theWindow = NULL;
  256.      
  257.     LListIterator iterator(myWindowList, iterate_FromStart);
  258.     CTridentWindow    *theSub;
  259.     while (iterator.Next(&theSub)) {
  260.         if (thePaneIDT == theSub->GetPaneID())
  261.             theWindow = theSub;
  262.         if (theWindow != nil) break;
  263.     }
  264.     return theWindow;
  265. }
  266.             
  267. void
  268. CTridentApp::CloseWindow(PaneIDT thePane)
  269. {
  270.     CTridentWindow* theWindow = (CTridentWindow*) this->LocateWindowByPaneIDT(thePane);
  271.     if (theWindow == NULL)
  272.         return;
  273.     
  274.     theWindow->SendQuit();
  275.         
  276.     switch(thePane)
  277.         {
  278.         case cmd_whoView:    //Bwindow   ..regular javelin
  279.             myWindowList.Remove(&theWindow);
  280.             break;
  281.         case cmd_uptimeView:    //Awindow     ..something neat and yet mysterious
  282.             myWindowList.Remove(&theWindow);
  283.             break;
  284.         }
  285.     //delete theWindow;
  286. }